package src.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Collection;
import java.util.List;

import javax.imageio.ImageIO;

import src.model.gameObject.PlayerGameObject;
import src.model.gameWorld.GameDataObject;
import src.model.gameWorld.Player;
import src.view.ViewHandler.DisplayType;
import src.view.ViewHandler.ImageType;

/**
 * <b>Overview</b>
 * The StructureViewport displays all of the current player's structures at a glance and assign missions to each or to groups of structures.
 *
 * <b>Responsibilities</b>
 * This viewport must allow a player to see all of his structures quickly and also assign individuals or groups different missions.
 *
 * <b>Collaborators</b>
 * Drawable - Subcontractor: The Drawable object displays this viewport to the screen.
 *
 * <b>Implementor</b> - Bruce
 * <b>Tester</b> - Tim
 *
 * @author Bruce
 */
public class StructureViewport extends Viewport
{

	public StructureViewport(ViewHandler vh, Drawable canvas)
	{
		super(vh, canvas, DisplayType.STRUCTURE);
	}

	/* (non-Javadoc)
	 * @see src.view.Viewport#draw()
	 */
	@Override
	protected void draw()
	{
		// Background
		BufferedImage image = getImage(ImageType.PAPER);
		AffineTransform at = new AffineTransform();
		at.scale((double)getWidth() / (double)image.getWidth(), (double)getHeight() / (double)image.getHeight());
		getCanvas().drawImage(image, at, null);

		// Title
		image = getImage(ImageType.SOS);
		at = new AffineTransform();
		at.scale((double)getWidth() / (double)image.getWidth(), 1.0);
		getCanvas().drawImage(image, at, null);

		Player currentPlayer = null;

		if(currentPlayer != null)
		{
			Collection<PlayerGameObject> objects = currentPlayer.getAllGameObjects();
			int y = 0;
			for(PlayerGameObject o : objects)
				if(o.getType().equals("UNIT"))
				{
					GameDataObject gdo = new GameDataObject(o);
					for(String s : gdo.getAllInfo().keySet())
					{
						drawString(s + ": " + gdo.getInfo(s), 50, (++y * 20));
					}
					++y;
				}
		}
	}

	/* (non-Javadoc)
	 * @see src.view.Viewport#getResizeDimension()
	 */
	@Override
	protected Dimension getResizeDimension()
	{
		return getCanvasDimensions();
	}

	/* (non-Javadoc)
	 * @see src.view.Viewport#getResizePoint()
	 */
	@Override
	protected Point2D getResizePoint()
	{
		return Point2D.origin();
	}
}